import { createRouter, RouteRecordRaw, createWebHashHistory } from 'vue-router'
import Layout from '@/layout/index.vue'
// 扩展继承属性
interface extendRoute {
  hidden?: boolean
}

import errorRouter from './modules/error'

// 异步组件
export const asyncRoutes = [
  ...errorRouter,
  {
    path: '/:pathMatch(.*)',
    redirect: '/404',
  },
]

/**
 * path ==> 路由路径
 * name ==> 路由名称
 * component ==> 路由组件
 * redirect ==> 路由重定向
 * alwaysShow ==> 如果设置为true，将始终显示根菜单，无论其子路由长度如何
 * hidden ==> 如果“hidden:true”不会显示在侧边栏中（默认值为false）
 * keepAlive ==> 设为true 缓存
 * meta ==> 路由元信息
 * meta.title ==> 路由标题
 * meta.icon ==> 菜单icon
 * meta.affix ==> 如果设置为true将会出现在 标签栏中
 * meta.breadcrumb ==> 如果设置为false，该项将隐藏在breadcrumb中（默认值为true）
 */

export const constantRoutes: Array<RouteRecordRaw & extendRoute> = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    hidden: true,
    meta: { title: '登录' },
  },
  {
    path: '/',
    name: 'layout',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: '/home',
        component: () => import('@/views/home/index.vue'),
        name: 'home',
        meta: { title: '数据展示', icon: 'DataAnalysis', keepAlive: true },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/accountControl',
    children: [
      {
        path: '/accountControl',
        component: () => import('@/views/accountControl/index.vue'),
        name: 'accountControl',
        meta: { title: '账户信息管理', icon: 'Pointer' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/noticeInfoSend',
    children: [
      {
        path: '/noticeInfoSend',
        component: () => import('@/views/noticeInfoSend/index.vue'),
        name: 'noticeInfoSend',
        meta: { title: '已发送通知查看', icon: 'Notification' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/noticeInfoRec',
    children: [
      {
        path: '/noticeInfoRec',
        component: () => import('@/views/noticeInfoRec/index.vue'),
        name: 'noticeInfoRec',
        meta: { title: '接收通知查看', icon: 'Notification' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/partyMember',
    children: [
      {
        path: '/partyMember',
        component: () => import('@/views/partyMember/index.vue'),
        name: 'partyMember',
        meta: { title: '党员管理', icon: 'Avatar' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/documentApproval',
    children: [
      {
        path: '/documentApproval',
        component: () => import('@/views/documentApproval/index.vue'),
        name: 'documentApproval',
        meta: { title: '文件审核', icon: 'Message' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/academyDataShow',
    children: [
      {
        path: '/academyDataShow',
        component: () => import('@/views/academyDataShow/index.vue'),
        name: 'academyDataShow',
        meta: { title: '学院数据展示', icon: 'DataAnalysis' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/academyMember',
    children: [
      {
        path: '/academyMember',
        component: () => import('@/views/academyMember/index.vue'),
        name: 'academyMember',
        meta: { title: '党员信息', icon: 'IceTea' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/branchControl',
    children: [
      {
        path: '/branchControl',
        component: () => import('@/views/branchControl/index.vue'),
        name: 'branchControl',
        meta: { title: '支部管理', icon: 'Monitor' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/createBranch',
    children: [
      {
        path: '/createBranch',
        component: () => import('@/views/createBranch/index.vue'),
        name: 'createBranch',
        meta: { title: '创建支部', icon: 'Platform' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/outerAPI',
    hidden: false,
    meta: { title: '看看展馆', icon: 'Sunset' },
    children: [
      {
        path: '/first',
        component: () => import('@/views/outerAPI/components/first.vue'),
        name: 'first',
        meta: { title: '奋进新时代', icon: 'View' },
      },
      {
        path: '/second',
        component: () => import('@/views/outerAPI/components/second.vue'),
        name: 'second',
        meta: { title: '中共三大会址', icon: 'View' },
      },
      {
        path: '/third',
        component: () => import('@/views/outerAPI/components/third.vue'),
        name: 'third',
        meta: { title: '广州起义', icon: 'View' },
      },
    ],
  },
]

const router = createRouter({
  // history: createWebHistory(process.env.BASE_URL), // history
  history: createWebHashHistory(), // hash
  routes: constantRoutes,
})

export default router
